{{- $count := default 5 (default .Params.relatedPostCount .Site.Params.relatedPostCount) -}}
{{- $sections := default (slice "posts") .Site.Params.mainSections -}}
{{- $relatedPosts := where (.Site.RegularPages.Related .) "Section" "in" $sections -}}
{{- if and $count $relatedPosts -}}
  {{- with ($relatedPosts | first $count) -}}
  <section class="related-posts row card component">
    <div class="card-header">
      <h2 class="card-title">{{ i18n "related_posts" }}</h2>
    </div>
    <div class="card-body">
      <ul class="post-list">
        {{- range . -}}
        <li>
          <a href="{{ .Permalink }}">{{ partial "helpers/title" . }}</a>
          <span class="float-end post-date">{{- partial "helpers/post-date" . -}}</span>
        </li>
        {{- end -}}
      </ul>
    </div>
  </section>
  {{- end -}}
{{- end -}}
